import request from '../utils/request'

// 获取图书分页列表
export function getBookList(params) {
  return request({
    url: '/books/page',
    method: 'get',
    params
  })
}

// 获取图书分类名称
export function getCategoryName(id) {
  return request({
    url: `/categories/${id}/name`,
    method: 'get'
  })
}

// 获取图书详情
export function getBookDetail(id) {
  return request({
    url: `/books/${id}`,
    method: 'get'
  })
}

// 添加图书
export function addBook(data) {
  return request({
    url: '/books',
    method: 'post',
    data
  })
}

// 修改图书
export function updateBook(data) {
  return request({
    url: `/books/${data.id}`,
    method: 'put',
    data
  })
}

// 删除图书
export function deleteBook(id) {
  return request({
    url: `/books/${id}`,
    method: 'delete'
  })
}

// 更新图书库存
export function updateBookStock(id, stock) {
  return request({
    url: `/books/${id}/stock`,
    method: 'put',
    params: { stock }
  })
}